import * as path from 'path';

import {
  createEcharts,
  createSolutionLineEcharts
} from '../util/image';

import { GroupAnswerItem } from './core/group-score.d';

/**
 * 创建PDF文字数据
 * @param allConclusionResult 所有分类成绩
 * @return {description: string} 13类症状描述
 */
export const createFileDescriptionList = (allConclusionResult: GroupAnswerItem[]) => {
  const descriptionList: string[] = allConclusionResult.map((
    itemConclusionResult
  ) => {
    const { description } = itemConclusionResult;
    if (!description) {
      throw new Error('无法获取反馈描述信息！');
    }
    return description;
  });
  /** 躯体化 */
  const physicalResult = descriptionList[0];
  /** 焦虑 */
  const mentalAnxiety = descriptionList[1];
  /** 抑郁 */
  const mentalDepression = descriptionList[2];
  /** 偏执 */
  const mentalParanoid = descriptionList[3];
  /** 精神病性 */
  const mentalPsychotic = descriptionList[4];
  /** 主观幸福感 */
  const mentalWellBeing = descriptionList[5];
  /** 工作负荷 */
  const stressWorkLoad = descriptionList[6];
  /** 公司管理 */
  const stressCompany = descriptionList[7];
  /** 与领导关系 */
  const stressLeaderShip = descriptionList[8];
  /** 与同事关系 */
  const stressColleagues = descriptionList[9];
  /** 与客户关系 */
  const stressCustomers = descriptionList[10];
  /** 与家庭关系 */
  const stressFamily = descriptionList[11];
  /** 应对方式 */
  const solutionResult = descriptionList[12];
  return {
    physicalResult,
    mentalAnxiety,
    mentalDepression,
    mentalParanoid,
    mentalPsychotic,
    mentalWellBeing,
    stressWorkLoad,
    stressCompany,
    stressLeaderShip,
    stressColleagues,
    stressCustomers,
    stressFamily,
    solutionResult
  };
};

/**
 * 创建反馈文件需要的图片
 * @param echartsData echarts数据
 * @param sumScore 总成绩
 * @param mergeUuid merge uuid
 * @return {imagePath: string} 图片路径
 */
export const createFileImage = (
  echartsData,
  sumScore: number,
  mergeUuid: string
) => {
  echartsData.forEach((item, index) => {
    const { conclusionsResult } = item;
    createEcharts(conclusionsResult, mergeUuid, index);
  });
  // 获取总结论图片
  const concludedImagePath = createSolutionLineEcharts(sumScore, mergeUuid);
  // 获取各类图片路径
  const physicalImagePath = path.resolve(__dirname, `../public/image/${mergeUuid}-1.png`);
  const mentalImagePath = path.resolve(__dirname, `../public/image/${mergeUuid}-2.png`);
  const stressImagePath = path.resolve(__dirname, `../public/image/${mergeUuid}-3.png`);
  const solutionImagePath = path.resolve(__dirname, `../public/image/${mergeUuid}-4.png`);
  return {
    concludedImagePath,
    physicalImagePath,
    mentalImagePath,
    stressImagePath,
    solutionImagePath
  };
};
